﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rbac.Contracts.DTO.InPut;
using Rbac.Contracts.DTO.OutPut;
using Rbac.Contracts.Interface;
using Rbac.Domain.Entity;

namespace Rbac.API.Controllers
{
	/// <summary>
	/// 角色
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	[Authorize]
	public class RoleController : ControllerBase
	{
		private readonly IRoleServer _roleServer;
		public RoleController(IRoleServer roleServer)
		{
			_roleServer = roleServer;
		}
		/// <summary>
		/// 角色查询
		/// </summary>
		/// <param name="roleName">角色名称</param>
		/// <returns></returns>
		[HttpGet]
		
		public Results<List<RoleOutPut>> SearchRoles(string? roleName)
		{
			return Results<List<RoleOutPut>>.DataResult(_roleServer.SearchRoles(roleName));

		}
		/// <summary>
		/// 添加
		/// </summary>
		/// <param name="role"></param>
		/// <returns></returns>
		[HttpPost]
		public Results<int> Add([FromBody]RoleInput role)
		{
			return Results<int>.DataResult(_roleServer.Add(role));
		}
		/// <summary>
		/// 修改
		/// </summary>
		/// <param name="role"></param>
		/// <returns></returns>
		[HttpPut]
		public Results<int> Update([FromBody]RoleInput role)
		{
			return Results<int>.DataResult(_roleServer.Update(role));
		}
		/// <summary>
		/// 删除
		/// </summary>
		/// <param name="idList"></param>
		/// <returns></returns>
		[HttpDelete]
		public Results<int> Delete([FromBody]List<int> idList)
		{
			return Results<int>.DataResult(_roleServer.Delete(idList.ToArray()));
		}
	}
}
